package com.frain.springcloud.controller;

import java.util.Random;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/springapi/testApi")
public class SpringTestApi {

    @Value("${server.port}")
    public int port;

    @RequestMapping("/getString")
    public String getString() {
        System.out.println("this  server port" + port + "  getString  method");
        return "String..value";
    }

    /**
     * 
     * @Title: timeThreeFinish 
     * @Description: 需要执行3秒完成 
     * @param @return
     * @param @throws InterruptedException 参数说明 
     * @return String 返回类型 
     * @throws 
     * @author frain
     * @date 2018年8月6日 上午10:16:26
     */
    @RequestMapping("/timeThreeFinish")
    @SuppressWarnings({ "unchecked", "static-access" })
    public String timeThreeFinish() throws InterruptedException {

        System.out.println("this  server port" + port + "  timeThreeFinish  method");
        Thread.currentThread().sleep(3000l);

        System.out.println("timeThreeFinish   3m  finish");

        return "timeThreeFinish";
    }

    /**
     * 
     * @Title: randomException 
     * @Description: 人品报错方法
     * @param @return
     * @param @throws Exception 参数说明 
     * @return String 返回类型 
     * @throws 
     * @author frain
     * @date 2018年8月6日 上午10:19:05
     */
    @RequestMapping("/randomException")
    public String randomException() throws Exception {

        System.out.println("this  server port" + port + "  randomException  method");

        if (new Random().nextInt(1000) % 2 == 0) {
            throw new Exception("执行异常");
        }

        System.out.println("randomException finish");
        return "randomException";

    }

}
